package com.bit.demo.demo2;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class userController {
    @RequestMapping("/login")
    //账号 zhangsan
    //密码 123456
    public Boolean login(String userName, String password, HttpSession session) {
        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return false;
        }
        if (!"zhangsan".equals(userName) || !"123456".equals(password)) {
            return false;
        }
        session.setAttribute("userName", userName);
        return true;
    }

    @RequestMapping("/getuserName")
    public String getuserName(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        if (StringUtils.hasLength(userName)) {
            return userName;
        }
        return " ";
    }
}
